import threading
import time

class SpinLock_mutex:
    def __init__(self):
        self._lock = threading.Lock()
        self._flag = False

    def acquire(self):
        while True:
            with self._lock:
                if not self._flag:
                    self._flag = True
                    return
            time.sleep(0.001)  # 防止过度占用CPU

    def release(self):
        with self._lock:
            self._flag = False